using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ground : BlockBase
{
    Renderer[] renderers;
    Material[] materials;
    Material chooseMaterial;

    protected override void Awake()
    {
        base.Awake();

        renderers = GetComponentsInChildren<Renderer>();

        materials = new Material[renderers.Length];
        for(int i = 0; i < renderers.Length; i++)
        {
            materials[i] = renderers[i].material;
        }
        chooseMaterial = Resources.Load<Material>("Choose_mat");
    }

    protected override void Update()
    {
        base.Update();
        if(LevelManager.ChooseBlock == gameObject)
        {
            ChooseThis();
        }
        else
        {
            DontChooseThis();
        }
    }

    void ChooseThis()
    {
        for (int i = 0; i < renderers.Length; i++)
        {
            renderers[i].material = chooseMaterial;
        }
    }

    void DontChooseThis()
    {
        for (int i = 0; i < renderers.Length; i++)
        {
            renderers[i].material = materials[i];
        }
    }
}
